<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>

    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>

    <style>
        .adminInfo{
            position: relative;
            top:10%;
            left:33%;
            font-size: 18px;
        }
        label{
            font-weight: normal;
        }
        .row{
            padding-bottom: 20px;
        }
        #confirm{
            position: relative;
            top:0px;
            left:90px;
        }
        #cancel{
            position: relative;
            top:0px;
            left:125px;
        }
    </style>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">钱包注册</strong>
            <small></small>
        </div>
    </div>

    <hr>

    <div class="am-g">
        <form class="adminInfo" style="padding-top: 20px;">
            <div class="row">
                <label>用户名称：</label><input type="text" id="name" disabled="disabled"></input>
            </div>

            <div class="row">
                <label>账号密码：</label><input type="password" id="pw" required></input>
            </div>

            <div class="row">
                <label>确认密码：</label><input type="password" id="pw1" required></input>
            </div>

            <!--<div class="row">
                <label>手机号码：</label><input type="text" id="phone"></input>
            </div>-->

            <div class="row">
                <div>
                    <a class="am-btn am-btn-primary" onclick="confirm()" id="confirm">确认</a>
                    <a class="am-btn am-btn-primary" onclick="cancel()" id="cancel">取消</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    //id从url得到
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];

    //根据uid获取用户名
    $(function(){
        $.ajax({
            type: 'post',
            url: '/admin/getInfo',
            data: {id:uid},
            dataType: 'json',
            success: function (mydata) {
                document.getElementById("name").value=mydata.name;
            },
            error: function () {
                alert("error");
            }
        })
    })

    function confirm() {
        var pw=document.getElementById("pw").value;
        var pw1=document.getElementById("pw1").value;
        if(pw!=pw1){
            alert("两次密码不一致，请重新输入");
        }
        else{
            $.ajax({
                type: 'post',
                url: '/wallet/register',
                data: {uid:uid,pw:pw},
                dataType: 'text',
                success: function (mydata) {
                    if(mydata=="true"){
                        //跳转到钱包记录，todo
                        window.location.href="/walletInfo?uid="+uid;
                    }
                },
                error: function () {
                    alert("钱包注册失败");
                }
            })
        }
    }

    function cancel() {
        location.reload();
    }

    //关闭弹窗页面
    function close() {
        window.parent.location.reload();
    }

    //解析url传值
    function getParameter() {
        var url=location.search;//获取url?后面的内容
        var result=new Object();
        if(url.indexOf("?")!= -1){
            var str=url.substr(1);
            strs=str.split("&");
            for(var i=0;i<strs.length;i++){
                result[strs[i].split("=")[0]]=decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</body>
</html>